package main

import (
	"fmt"
	"sync"
)

type Singleton struct {
	member int
}

var once sync.Once

var instance *Singleton

func getSingleton() *Singleton {
	once.Do(func() {
		fmt.Println("once")
		instance = &Singleton{}
		instance.member = 100
	})
	fmt.Println(instance.member)
	return instance
}

// func main() {
// 	var wg sync.WaitGroup
// 	size := 10
// 	wg.Add(size)
// 	for i := 0; i < size; i++ {
// 		go func() {
// 			defer wg.Done()
// 			instance = getSingleton()
// 		}()
// 	}
// 	wg.Wait()
// 	fmt.Println("main end~~~")
// }
